' style.bmx

Strict

Import "host.bmx"
Import "bytebuffer.bmx"
Import "nodeview.bmx"
Import "view.bmx"

Const NORMAL=0
Const COMMENT=1
Const QUOTED=2
Const KEYWORD=3

Function AddTextStyle:TTextStyle(parent:TDataNode,name$)
	Return New TTextStyle.ResetTextStyle(parent,name)
End Function

Function AddFontStyle:TFontStyle(parent:TDataNode,name$,fname$,fsize,fstyle)
	Return New TFontStyle.ResetFontStyle(parent,name$,fname$,fsize,fstyle)
End Function

Function AddColorStyle:TColorStyle(parent:TDataNode,name$,rgb)
	Return New TColorStyle.ResetColorStyle(parent,name,rgb)
End Function

Function AddGadgetStyle:TGadgetStyle(parent:TDataNode,name$)
	Return New TGadgetStyle.ResetGadgetStyle(parent,name)
End Function

Type TTextStyle Extends TPanel
	Field	label:TLabel
	Field	color:TColorButton
	Field	combo:TComboButton

	Method Format(textarea:TGadget,pos,length)
		Local	flags=Int(combo.toString())
		FormatTextAreaText textarea,color.red,color.green,color.blue,flags,pos,length
	End Method

	Method ResetTextStyle:TTextStyle(dad:TDataNode,name$)
		ResetPanel dad
		SetName name
		SetHorizontalFlow	
		label=AddLabel(name)
		color=AddColorButton("color",0)
		combo=AddComboButton("style",["Normal","Bold","Italic","BoldItalic"])
		Return Self
	End Method
End Type

Type TColorStyle Extends TPanel
	Field	label:TLabel
	Field	color:TColorButton

	Method Format(gadget:TGadget,pos,length)
'		SetGadgetColor gadget,color.red,color.green,color.blue
	End Method

	Method ResetColorStyle:TColorStyle(dad:TDataNode,name$,rgb)
		ResetPanel dad
		SetName name
		SetHorizontalFlow
		label=AddLabel(name)
		color=AddColorButton("color",rgb)
		Return Self
	End Method
End Type

Type TFontStyle Extends TPanel
	Field	label:TLabel
	Field	font:TFontButton

	Method Format(gadget:TGadget,pos,length)
'		SetGadgetfont gadget,font.font
	End Method

	Method ResetFontStyle:TFontStyle(dad:TDataNode,name$,fname$,fsize,fstyle)
		ResetPanel dad
		SetName name
		SetHorizontalFlow
		label=AddLabel(name)
		font=AddFontButton("font",fname,fsize,fstyle)
		Return Self
	End Method
End Type

Type TGadgetStyle Extends TPanel
	Field	fg:TColorStyle
	Field	bg:TColorStyle
	Field	font:TFontStyle

	Method Apply(gadget:TGadget)	
		SetGadgetFont gadget,font.font.font
		SetGadgetColor gadget,bg.color.red,bg.color.green,bg.color.blue,True
		SetGadgetColor gadget,fg.color.red,fg.color.green,fg.color.blue,False
	End Method
	
	Method Set(fg_rgb,bg_rgb,fname$,fsize)
		fg.color.set(fg_rgb)
		bg.color.set(bg_rgb)
		font.font.set(fname,fsize)
	End Method

	Method ResetGadgetStyle:TGadgetStyle(dad:TDataNode,name$)	'view:TView,name$)	'dad:TDataNode
		ResetPanel dad,name$
		font=AddFontStyle(Self,"Font","Courier",10,0)
		bg=AddColorStyle(Self,"Background Color",$404040)
		fg=AddColorStyle(Self,"Text Color",$ffffff)
		Layout
		Return Self
	End Method
End Type
